package com.example.demo.producer.service.impl;

import com.example.demo.common.domain.ChannelRead;
import com.example.demo.producer.domain.DeferredResultHolder;
import com.example.demo.producer.service.ActiveResService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.async.DeferredResult;

/**
 * @Auther Created by l.wang on 2019/4/4.
 */
@Service
public class ActiveResServiceImpl implements ActiveResService {

    @Autowired
    private DeferredResultHolder resultHolder;

    @Override
    public void dispose(ChannelRead resMessage) {
        DeferredResult<ChannelRead> channelRead = resultHolder.getMap().get(resMessage.getCode());
        System.out.println("返回处理：" + /*resultHolder.getMap().get(resMessage.getCode()) +"===="+*/ resultHolder.getMap().size());

        resultHolder.getMap().get(resMessage.getCode()).setResult(resMessage);
        System.out.println("返回："+ Thread.currentThread().getName());
    }

}
